/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-02-06
 * Time: 20:42
 */
public class test2 {
    /**
     * LeetCode 202  快乐数
     */

    public boolean isHappy(int n) {
        int slow = n;
        int fast = getNext(n);
        while(fast!=1 && slow!=fast){
            slow = getNext(slow);
            fast = getNext(getNext(fast));
        }
        return fast==1?true:false;
    }


    // 方法：得到下一位数
    public int getNext(int n){
        int total = 0;
        while(n>0){
            int d = n%10;
            total = d*d+total;
            n/=10;
        }
        return total;
    }
}
